package cn.springboot.osbulkparts.controller.warehouse;

import cn.springboot.osbulkparts.common.CommonResultInfo;
import cn.springboot.osbulkparts.common.OSLanguage;
import cn.springboot.osbulkparts.common.entity.CommonEntity;
import cn.springboot.osbulkparts.entity.*;
import cn.springboot.osbulkparts.service.GoodsListService;
import cn.springboot.osbulkparts.service.StockInfoService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/goods")
public class GoodsListController {

	@Autowired
	private GoodsListService goodsListService;

	@ApiOperation(value="页面初始化", notes="获取页面初始化数据")
	@GetMapping("/init")
	public Object initViews(@RequestHeader String lang){
		return goodsListService.initViews(lang,OSLanguage.localeToVueSuffix(lang));
	}


	@ApiOperation(value="获取发货信息列表信息", notes="查询发货信息列表")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "tDeliverInfoEntity", value = "发货信息实体对象", required = true, dataType = "body", paramType = "body"),
		@ApiImplicitParam(name = "pageNum", value = "分页-当前页码(默认1)", required = true, dataType = "String", paramType = "body"),
		@ApiImplicitParam(name = "pageSize", value = "分页-总页数(默认10)", required = true, dataType = "String", paramType = "body")
	})
	@GetMapping("/getGoodsList")
	public CommonResultInfo<?> getMaterialList(
			TDeliverInfoEntity tDeliverInfoEntity,
			@RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue="50") int pageSize,
			HttpServletRequest request, Authentication auth,
			@RequestHeader String lang){
		tDeliverInfoEntity.setLanguageFlag(OSLanguage.localeToTableSuffix(lang));
		return  goodsListService.getGoodsList( tDeliverInfoEntity,  pageNum,  pageSize,  auth,OSLanguage.localeToVueSuffix(lang));
	}

	@ApiOperation(value="获取发货信息列表信息", notes="查询发货信息列表")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "tDeliverInfoEntity", value = "发货信息实体对象", required = true, dataType = "body", paramType = "body"),
			@ApiImplicitParam(name = "pageNum", value = "分页-当前页码(默认1)", required = true, dataType = "String", paramType = "body"),
			@ApiImplicitParam(name = "pageSize", value = "分页-总页数(默认10)", required = true, dataType = "String", paramType = "body")
	})
	@GetMapping("/getGoodsListSplit")
	public CommonResultInfo<?> getMaterialListSplit(
			TDeliverInfoSplitEntity tDeliverInfoSplitEntity,
			@RequestParam(defaultValue = "1") int pageNum,
			@RequestParam(defaultValue="50") int pageSize,
			HttpServletRequest request, Authentication auth,
			@RequestHeader String lang){
		tDeliverInfoSplitEntity.setLanguageFlag(OSLanguage.localeToTableSuffix(lang));
		return  goodsListService.getGoodsListSplit( tDeliverInfoSplitEntity,  pageNum,  pageSize,  auth,OSLanguage.localeToVueSuffix(lang));
	}

	@ApiOperation(value="发货数据", notes="发货数据")
	@ApiImplicitParam(name = "commonEntity", value = "共同实体类", required = true, dataType = "body", paramType = "body")
	@PutMapping("/sendGoods")
	public CommonResultInfo<?> sendGoods(@RequestBody CommonEntity commonEntity, Authentication auth,@RequestHeader String lang){

		return  goodsListService.sendGoods(commonEntity,auth,OSLanguage.localeToVueSuffix(lang));
	}

	@ApiOperation(value="收货数据", notes="收货数据")
	@ApiImplicitParam(name = "commonEntity", value = "共同实体类", required = true, dataType = "body", paramType = "body")
	@PutMapping("/receivingGoods")
	public CommonResultInfo<?> receivingGoods(@RequestBody CommonEntity commonEntity, Authentication auth,@RequestHeader String lang){

		return  goodsListService.receivingGoods(commonEntity,auth,OSLanguage.localeToVueSuffix(lang));
	}

	@ApiOperation(value="删除数据", notes="删除数据")
	@ApiImplicitParam(name = "commonEntity", value = "共同实体类", required = true, dataType = "body", paramType = "body")
	@PutMapping("/deleteGoods")
	public CommonResultInfo<?> deleteGoods(@RequestBody CommonEntity commonEntity, Authentication auth,@RequestHeader String lang){

		return  goodsListService.deleteGoods(commonEntity,auth,OSLanguage.localeToVueSuffix(lang));
	}

	@ApiOperation(value="更新发货信息", notes="更新发货信息")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "tDeliverInfoEntity", value = "发货信息实体对象", required = true, dataType = "body", paramType = "body"),
	})
	@PutMapping("/updateGoods")
	public CommonResultInfo<?> updateGoods(@RequestBody TDeliverInfoEntity tDeliverInfoEntity, Authentication auth,@RequestHeader String lang){
		return  goodsListService.updateGoods(tDeliverInfoEntity,auth,OSLanguage.localeToVueSuffix(lang));
	}

	@ApiOperation(value="添加发货信息", notes="添加一条新的发货信息")
	@ApiImplicitParam(name = "tDeliverInfoEntity", value = "订单详情实体对象", required = true, dataType = "body", paramType = "body")
	@PostMapping("/addGoods")
	public CommonResultInfo<?> addGoods(@RequestBody TDeliverInfoEntity tDeliverInfoEntity, Authentication auth, @RequestHeader String lang){
		return goodsListService.addGood(tDeliverInfoEntity,auth,OSLanguage.localeToVueSuffix(lang));
	}

    @ApiOperation(value="根据物料号获得 物料的供应商信息和物料的数量", notes="根据物料号获得 物料的供应商信息和物料的数量")
    @GetMapping("/selectMaterialInfo")
    public Object selectMaterialInfo(@RequestParam String materialCode, Authentication auth,@RequestHeader String lang){
        return goodsListService.selectMaterialInfo(materialCode,auth,OSLanguage.localeToVueSuffix(lang));
    }

    @ApiOperation(value="根据id获得 发货信息", notes="根据id获得 发货信息")
    @GetMapping("/getDeliverInfo")
    public Object getDeliverInfo(String id,Authentication auth,@RequestHeader String lang){
        return goodsListService.getDeliverInfo(id,auth,lang,OSLanguage.localeToVueSuffix(lang));
    }
	@ApiOperation(value="根据合同号获得 提单号、装船日期、船期、应付款日期、实际付款日期", notes="根据id获得 发货信息")
	@GetMapping("/initInfoByContractNo")
	public Object getInitInfoByContractNo(String contractNo,Authentication auth,@RequestHeader String lang){
		return goodsListService.getInitInfoByContractNo(contractNo,auth,lang,OSLanguage.localeToVueSuffix(lang));
	}
    @ApiOperation(value="发货导出", notes="发货导出")
    @ApiImplicitParam(name = "mOrderInfoEntity", value = "实体对象", required = true, dataType = "body", paramType = "body")
    @PostMapping("/exportData")
    public Object downExcel( TDeliverInfoEntity tDeliverInfoEntity, @RequestHeader String lang) {
        tDeliverInfoEntity.setLanguageFlag(OSLanguage.localeToTableSuffix(lang));
        return goodsListService.downloadExcel(tDeliverInfoEntity,OSLanguage.localeToVueSuffix(lang));
    }

	@ApiOperation(value="拆分一条发货数据", notes="具体步骤 删除改数据，添加新数据")
	@ApiImplicitParam(name = "mOrderInfoEntity", value = "实体对象集合", required = true, dataType = "body", paramType = "body")
	@PostMapping("/split/{oldId}")
	public CommonResultInfo<?> splitGoods(@PathVariable String oldId,@RequestBody List<TDeliverInfoEntity> tDeliverInfoEntity, Authentication auth, @RequestHeader String lang){
		return goodsListService.splitGoods(oldId,tDeliverInfoEntity,auth,OSLanguage.localeToVueSuffix(lang));
	}
}
